<template>
  <view class="page-wallet">
    <view class="header">
      <view class="title">{{ $t('mine.我的钱包') }}</view>
      <uni-icons type="left" color="#ffffff" size="24" class="back-icon" @click="handleBack"></uni-icons>
    </view>
    <view class="wallet-card">
      <view class="money-wrapper">
        <view class="money-left">
          <!-- <view class="count">{{ walletInfo.availableBalance }}$</view> -->
          <view class="name">{{ $t('mine.我的余额') }}</view>
          <view class="desc">({{ $t('mine.可提现') }})</view>
        </view>
        <view class="money-right">{{ walletInfo.monneyBalance }}($)</view>
      </view>
      <view class="other-item">
        <view class="item-left">
          <view class="name">{{ $t('mine.项目质押金') }}</view>
        </view>
        <view class="item-right">{{ walletInfo.projectDeposit }}($)</view>
      </view>
      <view class="other-item">
        <view class="item-left">
          <view class="name">{{ $t('mine.代理质押金') }}</view>
        </view>
        <view class="item-right">
          <view class="value">{{ walletInfo.agentDeposit }}($)</view>
          <view class="desc">({{ returned }})</view>
        </view>
      </view>
      <view class="other-item">
        <view class="item-left">
          <view class="name">{{ $t('mine.冻结金额') }}</view>
        </view>
        <view class="item-right">{{ walletInfo.fozenBalance }}($)</view>
      </view>
    </view>
    <view class="options-wrapper">
      <view class="btn recharge" @click="handleRecharge">{{ $t('mine.充值') }}</view>
      <view class="btn withdraw" @click="handleWithdraw">{{ $t('mine.提现') }}</view>
      <view class="btn" @click="handleRechargeLog">{{ $t('mine.充值记录') }}</view>
      <view class="btn" @click="handleWithdrawLog">{{ $t('mine.提现记录') }}</view>
      <view class="btn" @click="handleBank">{{ $t('mine.银行卡') }}</view>
    </view>
  </view>
</template>
<script>
  import { wallet } from '@/api/wallet.js'
  import { getInfo } from '@/api/login'

  export default {
    data() {
      return {
        userInfo: {},
        walletInfo: {}
      }
    },
    onPullDownRefresh() {
      this.getWallet()
      this.getUserInfo()
      uni.stopPullDownRefresh()
    },
    computed: {
      returned() {
        if (this.userInfo.returned == 10) {
          return this.$t('mine.已返还结束')
        }
        return this.$t('mine.已返还') + this.userInfo.returned + this.$t('mine.月')
      }
    },
    methods: {
      getUserInfo() {
        this.$modal.loading('loading', 'loading')
        getInfo()
          .then((res) => {
            this.$modal.closeLoading()
            this.userInfo = res.result?.data || {}
          })
          .catch(() => {
            this.$modal.closeLoading()
          })
      },
      //返回
      handleBack() {
        // uni.navigateBack()
        this.$tab.switchTab('/pages/mine/index')
      },
      //充值
      handleRecharge() {
        this.$tab.navigateTo('/pages/mine/wallet/recharge')
      },
      //充值记录
      handleRechargeLog() {
        this.$tab.navigateTo('/pages/mine/wallet/rechargelog')
      },
      //提现
      handleWithdraw() {
        this.$tab.navigateTo('/pages/mine/wallet/withdraw')
      },
      //提现记录
      handleWithdrawLog() {
        this.$tab.navigateTo('/pages/mine/wallet/withdrawlog')
      },
      //银行卡
      handleBank() {
        this.$tab.navigateTo('/pages/mine/wallet/bank')
      },
      //获取钱包信息
      getWallet() {
        wallet().then((res) => {
          let { account } = res.result
          this.walletInfo = account || {}
        })
      }
    },
    created() {
      this.getUserInfo()
      this.getWallet()
    }
  }
</script>
<style lang="scss" scoped>
  .page-wallet {
    position: relative;
    .header {
      background-color: #31b2b5;
      text-align: center;
      height: 44px;
      line-height: 44px;
      position: fixed;
      top: 0;
      width: 100vw;
      color: #fff;

      font-size: 26rpx;
      z-index: 9;
      .back-icon {
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        font-weight: normal;
      }
    }
    .wallet-card {
      margin: 140rpx 20rpx 50rpx;
      border-radius: 5px;
      color: #fff;
      // background: linear-gradient(90deg, #91aae5 0%, #6083d6 100%);
      background: url('~@/static/images/mine/wallet-bg.png') no-repeat 80% 30%;
      .money-wrapper {
        height: 125px;
        display: flex;
        align-items: center;
        .money-left {
          width: 40%;
          display: flex;
          flex-direction: column;
          align-items: center;
          .count {
            font-size: 26rpx;
          }
          .name {
            font-size: 30rpx;
            margin: 10rpx 0;
          }
        }
        .money-right {
          flex: 1;
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 40rpx;
        }
      }
      .other-item {
        height: 60px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20rpx;
        border-top: 1px solid #ddd;
        .item-left {
          display: flex;
          align-items: center;
        }
        .item-right {
          display: flex;
          flex-direction: column;
          align-items: flex-end;
          .desc {
            font-size: 16rpx;
          }
        }
      }
    }
    .options-wrapper {
      .btn {
        height: 40px;
        border-radius: 20px;
        font-size: 16px;
        color: #666;
        line-height: 40px;
        text-align: center;
        width: 70vw;
        margin: 0 auto 20rpx;
        border: 1px solid #eee;
        &.recharge {
          color: #fff;
          background: #31b3b5;
        }
        &.withdraw {
          background: #eee;
        }
      }
    }
  }
</style>
